<?php
namespace app\home\controller;

use think\Controller;
use think\Db;
use think\Request;
use app\home\controller\Lists;
class Index extends Controller
{
    public function index()
    {
        //1楼广告
        $adverts_01=Db::table('tp_adversts')->where('sta',4)->select();
        $j=0;
        foreach($adverts_01 as $v)
        {
            $adverts_01[$j]['pic']='/uploads/adversts_pic/'.$v['pic'];
            $j++;
        }

        //1楼商品遍历(钻石)
        //$goods_datas=Db::query("SELECT * FROM tp_goods WHERE `goods_status`=?  and goods_class in(select id  from tp_category WHERE pid=?) or goods_class=?  order by create_time DESC",[0,42,42]);
        //1楼克拉钻
        $goods_datas=Db::table('tp_goods')->where('goods_class',61)->select();
        $j=0;
        foreach($goods_datas as $v)
        {
            $goods_datas[$j]['goods_pic']='/uploads/goods_pic/'.$v['goods_pic'];
            $j++;
        }

        //1楼北极光
        $goods_datas01=Db::table('tp_goods')->where('goods_class',62)->select();
        $j=0;
        foreach($goods_datas01 as $v)
        {
            $goods_datas01[$j]['goods_pic']='/uploads/goods_pic/'.$v['goods_pic'];
            $j++;
        }

        //1楼海淘
        $goods_datas02=Db::table('tp_goods')->where('goods_class',63)->select();
        $j=0;
        foreach($goods_datas02 as $v)
        {
            $goods_datas02[$j]['goods_pic']='/uploads/goods_pic/'.$v['goods_pic'];
            $j++;
        }

        //1楼裸钻
        $goods_datas03=Db::table('tp_goods')->where('goods_class',64)->select();
        $j=0;
        foreach($goods_datas03 as $v)
        {
            $goods_datas03[$j]['goods_pic']='/uploads/goods_pic/'.$v['goods_pic'];
            $j++;
        }

        //2楼广告
        $adverts_02=Db::table('tp_adversts')->where('sta',5)->select();
        $j=0;
        foreach($adverts_02 as $v)
        {
            $adverts_02[$j]['pic']='/uploads/adversts_pic/'.$v['pic'];
            $j++;
        }

        //2楼商品遍历（婚戒）
        //简约独钻
        //$goods2_datas=Db::query("SELECT * FROM tp_goods WHERE `goods_status`=?  and goods_class in(select id  from tp_category WHERE pid=?) or goods_class=?  order by create_time DESC",[0,43,43]);
        $goods2_datas=Db::table('tp_goods')->where('goods_class',44)->select();
        $j=0;
        foreach($goods2_datas as $v)
        {
            $goods2_datas[$j]['goods_pic']='/uploads/goods_pic/'.$v['goods_pic'];
            $j++;
        }

        //奢华群镶
        $goods2_datas01=Db::table('tp_goods')->where('goods_class',45)->select();
        $j=0;
        foreach($goods2_datas01 as $v)
        {
            $goods2_datas01[$j]['goods_pic']='/uploads/goods_pic/'.$v['goods_pic'];
            $j++;
        }

        //克拉钻戒
        $goods2_datas02=Db::table('tp_goods')->where('goods_class',46)->select();
        $j=0;
        foreach($goods2_datas02 as $v)
        {
            $goods2_datas02[$j]['goods_pic']='/uploads/goods_pic/'.$v['goods_pic'];
            $j++;
        }

        //纪念戒/花戒
        $goods2_datas03=Db::table('tp_goods')->where('goods_class',47)->select();
        $j=0;
        foreach($goods2_datas03 as $v)
        {
            $goods2_datas03[$j]['goods_pic']='/uploads/goods_pic/'.$v['goods_pic'];
            $j++;
        }

        //3楼广告
        $adverts_03=Db::table('tp_adversts')->where('sta',6)->select();
        $j=0;
        foreach($adverts_03 as $v)
        {
            $adverts_03[$j]['pic']='/uploads/adversts_pic/'.$v['pic'];
            $j++;
        }

        //3楼商品遍历(对戒)
        //3-1铂金对戒
        $goods3_datas=Db::table('tp_goods')->where('goods_class',49)->select();
        $j=0;
        foreach($goods3_datas as $v)
        {
            $goods3_datas[$j]['goods_pic']='/uploads/goods_pic/'.$v['goods_pic'];
            $j++;
        }

        //3-2男款对戒
        $goods3_datas01=Db::table('tp_goods')->where('goods_class',50)->select();
        $j=0;
        foreach($goods3_datas01 as $v)
        {
            $goods3_datas01[$j]['goods_pic']='/uploads/goods_pic/'.$v['goods_pic'];
            $j++;
        }

        //3-3女款对戒
        $goods3_datas02=Db::table('tp_goods')->where('goods_class',51)->select();
        $j=0;
        foreach($goods3_datas02 as $v)
        {
            $goods3_datas02[$j]['goods_pic']='/uploads/goods_pic/'.$v['goods_pic'];
            $j++;
        }

        //3-4情侣对戒
        $goods3_datas03=Db::table('tp_goods')->where('goods_class',65)->select();
        $j=0;
        foreach($goods3_datas03 as $v)
        {
            $goods3_datas03[$j]['goods_pic']='/uploads/goods_pic/'.$v['goods_pic'];
            $j++;
        }

        //3-5热销款式
        $goods3_datas04=Db::table('tp_goods')->where('goods_class',52)->select();
        $j=0;
        foreach($goods3_datas04 as $v)
        {
            $goods3_datas04[$j]['goods_pic']='/uploads/goods_pic/'.$v['goods_pic'];
            $j++;
        }

        //3楼广告
        $adverts_04=Db::table('tp_adversts')->where('sta',7)->select();
        $j=0;
        foreach($adverts_04 as $v)
        {
            $adverts_04[$j]['pic']='/uploads/adversts_pic/'.$v['pic'];
            $j++;
        }

        //4楼商品遍历(配饰)
        //$goods4_datas=Db::query("SELECT * FROM tp_goods WHERE `goods_status`=?  and goods_class in(select id  from tp_category WHERE pid=?) or goods_class=?  order by create_time DESC",[0,53,53]);
       //4-1挂坠
        $goods4_datas=Db::table('tp_goods')->where('goods_class',54)->order('create_time DESC')->select();
        $j=0;
        foreach($goods4_datas as $v)
        {
            $goods4_datas[$j]['goods_pic']='/uploads/goods_pic/'.$v['goods_pic'];
            $j++;
        }

        //4-2项链坠
        $goods4_datas01=Db::table('tp_goods')->where('goods_class',55)->order('create_time DESC')->select();
        $j=0;
        foreach($goods4_datas01 as $v)
        {
            $goods4_datas01[$j]['goods_pic']='/uploads/goods_pic/'.$v['goods_pic'];
            $j++;
        }

        //4-3耳钉
        $goods4_datas02=Db::table('tp_goods')->where('goods_class',56)->order('create_time DESC')->select();
        $j=0;
        foreach($goods4_datas02 as $v)
        {
            $goods4_datas02[$j]['goods_pic']='/uploads/goods_pic/'.$v['goods_pic'];
            $j++;
        }

        //4-4手链
        $goods4_datas03=Db::table('tp_goods')->where('goods_class',57)->order('create_time DESC')->select();
        $j=0;
        foreach($goods4_datas03 as $v)
        {
            $goods4_datas03[$j]['goods_pic']='/uploads/goods_pic/'.$v['goods_pic'];
            $j++;
        }

        //4-5手镯
        $goods4_datas04=Db::table('tp_goods')->where('goods_class',58)->order('create_time DESC')->select();
        $j=0;
        foreach($goods4_datas04 as $v)
        {
            $goods4_datas04[$j]['goods_pic']='/uploads/goods_pic/'.$v['goods_pic'];
            $j++;
        }

        //4-6项链
        $goods4_datas05=Db::table('tp_goods')->where('goods_class',59)->order('create_time DESC')->select();
        $j=0;
        foreach($goods4_datas05 as $v)
        {
            $goods4_datas05[$j]['goods_pic']='/uploads/goods_pic/'.$v['goods_pic'];
            $j++;
        }

        //轮播图遍历
        $picture_datas=Db::table('tp_picture')->limit(5)->order('create_time DESC')->select();
        $k=0;
        foreach($picture_datas as $v)
        {
            $picture_datas[$k]['picture_pic']='/uploads/picture_pic/'.$v['picture_pic'];
            $k++;
        }

        //公告遍历操作
        $notice_datas=Db::table('tp_notices')->limit(4)->order('create_time DESC')->select();
        $i=0;
        foreach($notice_datas as $v)
        {
            $notice_datas[$i]['create_time']=date('Y-m-d',$v['create_time']);
            $notice_datas[$i]['update_time']=date('Y-m-d',$v['update_time']);
            $i++;
       }

        //广告遍历操作
        $adversts_datas=Db::table('tp_adversts')->order('id DESC')->select();
        $j=0;
        foreach($adversts_datas as $v)
        {
            $adversts_datas[$j]['pic']='/uploads/adversts_pic/'.$v['pic'];
            $j++;
        }
        $this->assign('adverts_02', $adverts_02);
        $this->assign('adverts_01', $adverts_01);

        $this->assign('goods4_datas01',$goods4_datas01);
        $this->assign('goods4_datas02',$goods4_datas02);
        $this->assign('goods4_datas03',$goods4_datas03);
        $this->assign('goods4_datas04',$goods4_datas04);
        $this->assign('goods4_datas05',$goods4_datas05);
        $this->assign('goods4_datas',$goods4_datas);

        $this->assign('goods3_datas01',$goods3_datas01);
        $this->assign('goods3_datas02',$goods3_datas02);
        $this->assign('goods3_datas03',$goods3_datas03);
        $this->assign('goods3_datas04',$goods3_datas04);
        $this->assign('goods3_datas',$goods3_datas);

        $this->assign('goods2_datas01',$goods2_datas01);
        $this->assign('goods2_datas02',$goods2_datas02);
        $this->assign('goods2_datas03',$goods2_datas03);
        $this->assign('goods2_datas',$goods2_datas);

        $this->assign('goods_datas01',$goods_datas01);
        $this->assign('goods_datas02',$goods_datas02);
        $this->assign('goods_datas03',$goods_datas03);
        $this->assign('goods_datas',$goods_datas);
        $this->assign('picture_datas',$picture_datas);
        $this->assign('adversts_datas',$adversts_datas);
        $this->assign('notice_datas',$notice_datas);
       return $this->fetch('index/index');
    }
    //全局的商品搜索
    public function postsearch(Request $request){
        $search=$request->param('search');
        $list_datas=Db::name('goods')->where('goods_name','like',"%{$search}%")->select();
        $j=0;
        foreach($list_datas as $v)
        {
            $list_datas[$j]['goods_pic']='/uploads/goods_pic/'.$v['goods_pic'];
            $j++;
        }
        $this->assign('list_datas',$list_datas);
        return $this->fetch('lists/search');

    }

}
